package zhh.tangbao.auxiliary.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import zhh.tangbao.auxiliary.dto.opinion.OpinionQueryDto;
import zhh.tangbao.auxiliary.entity.SystemOpinion;
import zhh.tangbao.auxiliary.vo.opinion.OpinionInfoVo;
import zhh.tangbao.auxiliary.vo.opinion.OpinionPageVo;
import zhh.tangbao.system.entity.PagerEntity;
import zhh.tangbao.wechat.dto.opinion.UserOpinionQueryDto;
import zhh.tangbao.wechat.vo.opinion.UserOpinionListItemVo;

import java.util.Collection;
import java.util.List;

/**
 * <p>
 * 描述
 * </p>
 *
 * @author 粥灰灰
 * <p>2023/4/26</p>
 */

@Repository
@Mapper
public interface SystemOpinionDao extends BaseMapper<SystemOpinion> {

    int insertBatchSomeColumn(Collection<SystemOpinion> opinions);

    List<OpinionPageVo> listOpinionPageVos(@Param("pager") PagerEntity<OpinionPageVo> pager, @Param("dto") OpinionQueryDto dto);

    Long count(@Param("dto") OpinionQueryDto dto);

    OpinionInfoVo getOpinionInfoVo(@Param("id") String id);

    @Select("SELECT so.id, sot.name type_label, so.title, so.already_response " +
            "FROM system_opinion so " +
            "JOIN system_opinion_type sot ON so.type_id = sot.id " +
            "WHERE so.record_user_id = #{dto.userId} " +
            "ORDER BY so.record_time DESC " +
            "LIMIT #{dto.firstNum}, #{dto.pageSize}")
    List<UserOpinionListItemVo> listUserOpinionListItemVos(@Param("dto") UserOpinionQueryDto dto);
}
